#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=2e5+1000;
typedef long long LL;
const LL mod=1e9+7;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
LL a[maxn],b[maxn];
LL p[maxn];
map<LL,LL>map1;
LL ksm(LL a,LL k){
    LL res=1;
    while(k>0){
        if(k&1) res=res*a%mod;
        k>>=1;
        a=a*a%mod;
    }
    return res%mod;
}
int main(void)
{
  ///cin.tie(0);std::ios::sync_with_stdio(false);
  LL n,q;cin>>n>>q;
  for(LL i=1;i<=n;i++) cin>>a[i];
  LL gcd=0;
  for(LL i=1;i<=n;i++) gcd=__gcd(gcd,a[i]);
  for(LL i=1;i<=n;i++) b[i]=a[i]/gcd;
  for(LL i=1;i<=n;i++){
    LL temp=b[i];
    for(LL j=2;j<=sqrt(temp);j++){
        LL tmp=0;
        if(temp%j==0){
            while(temp>0){
                temp/=j;
                p[j]++;
            }
        }
    }
    if(temp>1) p[temp]++;
  }
   for(LL i=1;i<=2e5;i++){
     map1[i]+=p[i];
   }

   while(q--){
      LL i,x;cin>>i>>x;
      LL temp=x;
      vector<pair<LL,LL>>v;
      for(LL j=2;j<=sqrt(x);j++){
        LL times=0;
        if(x%j==0){
            x/=j;
            times++;
        }
        if(times>0) v.push_back({j,times});
      }
      if(x>1) v.push_back({x,(LL)1});
      LL ans=gcd;
      LL res=1;
      for(auto i:v){
         LL pp=0x3f3f3f3f;
         LL val=-1;
         if(map1.count(i.first)){
            pp=min(i.second,map1[i.first]);
            val=i.first;
            map1[i.first]-=pp;
         }

         if(pp!=0x3f3f3f3f){
            res=(res%mod*ksm(val,pp)%mod)%mod;
         }
      }
      ans=(ans%mod*res%mod)%mod;
      gcd=ans;
      cout<<ans<<"\n";
   }
return 0;
}
